package com.example.waitdemo.controller;

import com.example.waitdemo.config.ClassNotNull;
import com.example.waitdemo.config.StringNullRegex;
import com.example.waitdemo.config.jiang;
import com.example.waitdemo.pojo.UserProperty;
import com.example.waitdemo.utils.HttpResult;
import com.example.waitdemo.utils.WaitUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * TODO
 *
 * @ClassName WaitController
 * @Author xiaojiang
 * @Date 2021/10/21 下午 18:00
 */
@Log4j2
@RestController
@RequiredArgsConstructor
@RequestMapping("/wait")
public class WaitController {

    final UserProperty userProperty;

    /**
     *  TODO  模拟接口入参
     *
     * @Author 江
     * @Date 2021/10/21 下午 18:02
     */
    @RequestMapping(value = "/v1", method = RequestMethod.GET)
    public HttpResult test1(@RequestParam("userId") String userId, HttpServletRequest request, HttpServletResponse response){
        log.info("进入v1===");
        String method = null;
        try {
            method = new WaitUtil().method(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return HttpResult.newSuccess().add("data",method);
    }

    /**
     *  TODO  模拟查询到了数据，进行线程唤醒
     *
     * @Author 江
     * @Date 2021/10/21 下午 18:09
     */
    @RequestMapping(value = "/v2", method = RequestMethod.GET)
    public HttpResult test2(@RequestParam("userId")String userId,HttpServletRequest request, HttpServletResponse response){

        new WaitUtil().startUdpServer(userId);

        return HttpResult.newSuccess();
    }

    @RequestMapping(value = "/test",method = RequestMethod.GET)
    //@jiang(description = "测试")
    @StringNullRegex
    public HttpResult test(String userId, Integer usrId){
        String name = userProperty.getName();
        System.out.println("名字 = " + name);
        Integer age = userProperty.getAge();
        System.out.println("年龄 = " + age);
        Integer qq = userProperty.getQq();
        System.out.println("QQ = " + qq);

        return HttpResult.newSuccess();
    }

    @RequestMapping(value = "/testTwo",method = RequestMethod.GET)
    @ClassNotNull
    public HttpResult testTwo(UserProperty userProperty){
        String name = userProperty.getName();
        System.out.println("名字 = " + name);
        Integer age = userProperty.getAge();
        System.out.println("年龄 = " + age);
        Integer qq = userProperty.getQq();
        System.out.println("QQ = " + qq);

        return HttpResult.newSuccess();
    }

}
